package cn.jjxx.shiro.session.config;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
 

/**
 * reids 配置
 *@Title PropertyUtils.java
 *@description TODO
 *@time 2020年7月16日 下午12:43:13
 *@author YAOXIONG
 *@version 1.0
 *
 */ 
public class PropertyUtils { 
	static{
		loadProps();
	}
	private static Properties props;
	synchronized static private void loadProps(){
		props = new Properties();
		InputStream in = null;
		try {
			in = PropertyUtils.class.getClassLoader().getResourceAsStream("redis.properties");
			props.load(in);
		} catch (FileNotFoundException e) {
		} catch (IOException e) {
		} finally {
			try {
				if(null != in) {
					in.close();
				}
			} catch (IOException e) {
			}
		}
	}

	public static String getProperty(String key){
		if(null == props) {
			loadProps();
		}
		return props.getProperty(key);
	}

	public static String getProperty(String key, String defaultValue) {
		if(null == props) {
			loadProps();
		}
		return props.getProperty(key, defaultValue);
	}

	public static void main(String[] args) {
		String b = PropertyUtils.getProperty("redis.port");
		System.out.println(b);
	}  
}